package graduate.wangyaqi.Question;


import graduate.wangyaqi.Exam.Exam;
import graduate.wangyaqi.OnlyQuestions.OnlyQuestions;
import graduate.wangyaqi.OnlyQuestions.OnlyQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Optional;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping(path="/Questions")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @GetMapping(path="/findById")
    public Optional<Question> findById(Long aLong){
        return questionService.findById(aLong);
    }

    @GetMapping(path="/getAll")
    public Iterable<Question> getAll(){
        return questionService.getAll();
    }

    @PostMapping(path="/insert")
    public boolean InsertQuestion(@RequestBody  Question item){
        item.setQuestionTime(new Date());
        questionService.save(item);
        return true;
    }
}
